import time

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as e
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.webdriver import WebElement

TIMEOUT=10
class Base():
    def __init__(self,driver):
        self.driver=driver

    #进入网站
    def goto(self,url):
        self.driver.get(url)

    #等待点击
    def wait_click(self,loc,timeout=None)->WebElement:
        timeout=TIMEOUT if timeout is None else timeout
        wait=WebDriverWait(self.driver,timeout=timeout)
        return wait.until(e.element_to_be_clickable(loc))

    #等待文本
    def wait_text(self,loc,timeout=None)->WebElement:
        timeout=TIMEOUT if timeout is None else timeout
        wait=WebDriverWait(self.driver,timeout=timeout)
        return wait.until(e.visibility_of_element_located(loc))

    #点击
    def click(self,loc):
        self.wait_click(loc).click()

    #输入
    def send_keys(self,loc,text):
        self.wait_click(loc).send_keys(text)

    #文本
    def text(self,loc):
        return self.wait_text(loc).text

    #等待时间
    def sleep(self):
        time.sleep(7)